package com.dana.friend.controller.exam;

import com.core.constants.CacheConstant;
import com.core.constants.Constants;
import com.core.controller.BaseController;
import com.core.domain.Result;
import com.core.domain.TableDataInfo;
import com.core.utils.ThreadLocalUtils;
import com.dana.friend.domain.exam.dto.QueryExamDTO;
import com.dana.friend.service.exam.IExamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {
    @Autowired
    private IExamService examService;

    /**
     * 获取题目列表,从数据库中获取
     *
     * @param queryExamDTO
     * @return
     */
    @GetMapping("/semiLogin/list")
    public TableDataInfo list(QueryExamDTO queryExamDTO) {
        return getTableDataInfo(examService.getList(queryExamDTO));
    }

    /**
     * 从redis中获取竞赛列表
     * @param queryExamDTO
     * @return
     */
    @GetMapping("/semiLogin/redis/list")
    public TableDataInfo redisList(QueryExamDTO queryExamDTO) {
        return examService.getRedisList(queryExamDTO);
    }

    /**
     * 返回的id为String是因为前端接收的时候如果是Long可能会有问题
     * @param examId
     * @return
     */
    @GetMapping("/getFirstQuestion")
    public Result<String> getFirstQuestion(Long examId){
        return Result.ok(examService.getFirstQuestion(examId));
    }

    /**
     * 竞赛中上一题
     * 将题目id缓存到redis中,根据题目id获取上下题
     * @param questionId
     * @return
     */
    @GetMapping("/preQuestion")
    public Result<String> preQuestion(Long examId,Long questionId){
        return Result.ok(examService.preQuestion(questionId,examId));
    }
    /**
     * 竞赛中下一题
     * 将题目id缓存到redis中,根据题目id获取上下题
     * @param questionId
     * @return
     */
    @GetMapping("/nextQuestion")
    public Result<String> nextQuestion(Long examId,Long questionId){
        return Result.ok(examService.nextQuestion(questionId,examId));
    }
}